package Function.ItemUse;

import VWorldGameStudio.FCItem;
import VWorldGameStudio.FCPlayerInfo;
import VWorldGameStudio.FCTank;

import java.util.HashMap;

import static FCRendering.FCRMaster.itemLib;

//道具物品使用集合方法
public class FCItemUseCenter {
   private static FCItemUseCenter center;
    static {
        center = new FCItemUseCenter();
    }

    public static FCItemUseCenter getIn(){
        return center;
    }

    DoNothingItemUse nothingItemUse = new DoNothingItemUse();

    private HashMap<String, AItemUse> hummanItemTypeFunctions = new HashMap<>();
    private HashMap<String, AItemUse> tankItemTypeFunctions = new HashMap<>();
    private HashMap<String, AItemUse> itemNamesFunctions = new HashMap<>();
    String[] weaponTypes = new String[]{"gun1","gun2","shell","se"};
    /**
     * { "food", "drug", "tool", "throw", "arm", "hat", "jacket", "pants", "shoes", "plotItem","artwork","wantedPic","book","key"},
     * { "gun1", "gun2", "plate", "shell", "engine", "Cdevice", "chassis", "radar", "other","se"}
     *   //TODO 维护者要参考这里填充物品使用
     * 修理包属于坦克 other
     */
    private FCItemUseCenter(){
        //针对类型
        hummanItemTypeFunctions.put("food", new FoodAndDrugTypeItemUse());
        hummanItemTypeFunctions.put("drug", new FoodAndDrugTypeItemUse());
        hummanItemTypeFunctions.put("key", new KeyTypeItemUse());
        tankItemTypeFunctions.put("plate", new PlateTypeItemUse());
        tankItemTypeFunctions.put("throw", new TrowTypeItemUse());
        WeaponTypeItemUse weaponTypeItemUse = new WeaponTypeItemUse();
        for(int i = 0; i< weaponTypes.length; i++){
            //包含了炸 弹，焰 幕 弹,铁弹，散 弹，汽油弹，流弹，榴 弹,钢弹，毒气弹,催眠弹,臭 弹,水泥弹
            tankItemTypeFunctions.put(weaponTypes[i], weaponTypeItemUse);
        }
        hummanItemTypeFunctions.put("arm", weaponTypeItemUse);
        //针对名称
        ToolTanCheYi toolTanCheYi = new ToolTanCheYi();
        itemNamesFunctions.put("tanCheYiA", toolTanCheYi);
        itemNamesFunctions.put("tanCheYiB", toolTanCheYi);
        itemNamesFunctions.put("tanCheYiC", toolTanCheYi);
        itemNamesFunctions.put("mieHuoQi", new ToolMieHuoQi());
        itemNamesFunctions.put("penWuJi", new ToolPenWuJi());
        itemNamesFunctions.put("nuanBaoBao", new ToolNuanBaoBao());
        itemNamesFunctions.put("tongZheng", new ToolTongZheng());
        itemNamesFunctions.put("xiaofangShuan", new ToolXiaoFangShuan());
        itemNamesFunctions.put("huaBan", new ToolHuaBan());
        itemNamesFunctions.put("reparPack", new ToolRepairBag());
        itemNamesFunctions.put("junHao", new ToolJunHao());
        itemNamesFunctions.put("worldMap", new ToolWroldMap());
        itemNamesFunctions.put("miCaiTiao", new ToolMiCaiTiao());
        itemNamesFunctions.put("tankYaoXiang", new ToolTankYaoXiang());
        itemNamesFunctions.put("shiLa", new ToolShiLa());
        itemNamesFunctions.put("nuanFengJi", new ToolNuanFengJi());
        itemNamesFunctions.put("lengFengJi", new ToolLengFengJi());
        itemNamesFunctions.put("qiShan", new ToolQiShan());
        itemNamesFunctions.put("kongTiaoJi", new ToolKongTiaoJi());
        itemNamesFunctions.put("dianBaoHuPing", new ToolDianBaoHuPing());
        itemNamesFunctions.put("zhuangJiBan", new ToolZhuangJiBan());
        itemNamesFunctions.put("tankChuanzhen", new ToolChuanZhengJi());
        itemNamesFunctions.put("banShou", new ToolBanShou());
        itemNamesFunctions.put("tankCardA", new ToolTankCard());
        itemNamesFunctions.put("MMWGameVip", new ToolMMWGameVip());
        itemNamesFunctions.put("qiXiPingBiQi", new ToolqiXiPingBiQi());
        itemNamesFunctions.put("zaiShengWan", new FoodZaiShengWan());
        itemNamesFunctions.put("qianBao", new ArmQianBao());
        itemNamesFunctions.put("cowboyRope", new ToolCowboyRope());
    }


    public AItemUse findItemUseMethod(FCPlayerInfo p, FCTank t, String itemName, int position, boolean isIntank){
        AItemUse  r = itemNamesFunctions.get(itemName); //先从名字上找
        FCItem item = itemLib.getItemOfID(itemName);
        if (r == null) {//再类型上找
            r = item.getCatalog().equals("tank") ? tankItemTypeFunctions.get(item.getType()) : hummanItemTypeFunctions.get(item.getType());
        }
        if(r == null){//实在没就不能用的物品
            r = nothingItemUse;
        }
        System.out.println("findItemUseMethod "+r.getClass().getSimpleName());
        r.setUpIt(p, t, itemName, position, isIntank);
        return r;
    }

}
